//
//  UIBarButtonIten+Extension.swift
//  Weibo
//
//  Created by FF on 16/12/11.
//  Copyright © 2016年 Cold Wind. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize , 默认16
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否返回按钮，如果是加上剪头图片
    ///   - return: UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector,isBack: Bool = false) {
        

//        
//         Swfit 调用 OC 返回 instancetype 的方法，判断不出可选！   直接声明类型即可， 懒加载也有此情况！
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBack {
            let image = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: image), for: .normal)
            btn.setImage(UIImage(named: image + "_highlighted"), for: .highlighted)
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        //btn.titleLabel?.textAlignment = NSTextAlignment.right
        //使文字距离做边框保持10个像素的距离。
        //btn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10)
        btn.sizeToFit()
        self.init(customView: btn)
    }
}
